<template>
  <div class="app-container">
    <el-form ref="queryForm" :inline="true" label-width="68px">
      <el-form-item prop="name">
        <div class="project-select" @click="selectProject">
          <span>
            <span style="color: #606266;" v-if="projectName">{{projectName}}</span>
            <span style="color: #C0C4CC;" v-else>项目</span>
          </span>
          <span v-if="projectName" class="icon" style="color: #C0C4CC;" @click.stop="clearProject"><i class="el-icon-circle-close"></i></span>
        </div>
      </el-form-item>
      <el-form-item prop="name">
        <el-select v-model="enableStatus" placeholder="状态" clearable>
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="audit-btn">
      <el-button type="primary" size="mini" @click="add">新增</el-button>
    </div>
    <el-table v-loading="loading" :data="auditList">
      <el-table-column label="项目ID" align="center" width="200" prop="projectId" />
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="更新时间" align="center" prop="updateTime" width="200" />
      <el-table-column label="状态" align="center" prop="enableStatus">
        <template v-slot="scope">
          <div>{{ scope.row.enableStatus==1?'启用':'停用' }}</div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="200">
        <template v-slot="scope">
          <el-button size="mini" type="text" @click="changeState(scope.row)">{{ scope.row.enableStatus==1?'停用':'启用' }}</el-button>
          <el-button size="mini" type="text" @click="editAudit(scope.row)" :disabled="scope.row.enableStatus==0?false:true">编辑</el-button>
          <el-button size="mini" type="text" @click="deleteAudit(scope.row.projectMonitorId)" :disabled="scope.row.enableStatus==0?false:true">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="pagination.pageNum" :limit.sync="pagination.pageSize" @pagination="getList" />
    <DailySummary ref="dailySummary" @update="getList" />
    <ProjectConfigModal ref="projectConfigRef" @update="changeProject" />
  </div>
</template>
<script>
import { queryProjectMonitor,changeStatus,deleteProjectMonitor } from '@/api/singleraView/dailySummary'
import DailySummary from '@/views/singleraView/dailySummary/addDailySummary.vue'
import ProjectConfigModal from '@/views/auditManagement/projectConfiguration/projectConfigModal.vue'
export default {
  components: {
    DailySummary,
    ProjectConfigModal
  },
  data () {
    return {
      // 遮罩层
      loading: false,
      // 总条数
      total: 0,
      // 参数表格数据
      auditList: [],
      pagination: {
        pageNum: 1,
        pageSize: 10,
      },
      projectName: '',
      enableStatus: '',
      options: [{
          value: '0',
          label: '停用'
        }, {
          value: '1',
          label: '启用'
        }],
    };
  },
  mounted() {
    this.getList()
  },
  methods: {
    getList () {
      let params = {
        ...this.pagination
      }
      params.projectName = this.projectName
      params.enableStatus = this.enableStatus
      queryProjectMonitor(params).then(res => {
        this.auditList = res.rows
        this.total = res.total
      })
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.pagination.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.enableStatus = '';
      this.projectName = '';
      this.pagination = {
        pageNum: 1,
        pageSize: 10,
      }
      this.handleQuery()
    },
    selectProject(){
      this.$refs.projectConfigRef.getInit()
    },
    changeProject(multi){
      this.projectName = multi.name;
      this.getList()
    },
    clearProject(){
      this.enableStatus = ''
      this.projectName = ''
    },
    add(){
      this.$refs.dailySummary.init()
    },
    changeState(row){
      changeStatus(row.projectMonitorId).then(res => {
        this.getList()
      })
    },
    editAudit(row) {
      this.$refs.dailySummary.init(row)
    },
    deleteAudit(id) {
      this.$confirm('是否确认删除?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return deleteProjectMonitor(id);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    checkDetail(row){
      this.$refs.taskDetailRef.init(row)
    }
  }
}
</script>
<style scoped lang="scss">
.audit-btn{
  margin-bottom: 20px;
  display: flex;
  flex-direction: row;
  .upload-demo{
    margin-right: 10px;
  }
}
.project-select{
  width: 200px;
  height: 34px;
  line-height: 34px;
  background: #FFFFFF;
  border-radius: 5px;
  color: #C0C4CC;
  padding: 0 20px 0 15px;
  cursor: pointer;
  border: 1px solid #DCDFE6;
  position: relative;
  overflow: hidden;
  .icon{
    position: absolute;
    right: 5px;
    top: 0;
  }
}
</style>

